<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/11/7
  Time: 23:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>
<%@ page import="com.limao.servlet.WebFunction" %>
<%@ page import="com.limao.DBDataClass.CrowdUserAuthClass" %>
<%@ page import="com.limao.DBDataClass.CrowdMAHomeClass" %>

<%
    String userid=CacheClass.isLogin(request,response);
    if (CacheClass.getIntValue(userid) == 0) {
        out.println("<script language='JavaScript'>alert('您还没有登陆！');location.href=document.referrer;</script>"); //后退并刷新
        return;
    }
    CrowdUserAuthClass user = WebFunction.getUserInfo(request, response);
    if (user == null) {
        out.println("<script language='JavaScript'>alert('用户不存在，或被平台禁用，请联系客服！');window.history.back(-1);</script>");
        return;
    }

    // 白条首页信息
    CrowdMAHomeClass cmahc = WebFunction.getMAHomeInfo(request, response);
%>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单抵押</title>
</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc c3 f18">
        <span class="pa" style="left: 2px;" onclick="javascript:history.back();"><img src="mb/images/top_back.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
        订单抵押
    </div>
</div>

<div class="container db jz" style="padding-bottom: 0;padding-top: 41px;">
    <div id="container" class="w100 of">

    </div>

    <section class="bmLast bcf w100 of">
        <h4 class="f16 c3">合计</h4>
        <p class="tc">
            <span class="f14 c6">抵押资产：</span><span class="cred f12">&yen;</span><span
                id="totalrmb" class="cred f20 fb">0.00</span>
        </p>
        <p class="tc">
            <span class="f14 c6">借贷资金：</span><span class="c3 f12">&yen;</span><span id="totalowenrmb" class="f20 c3 fb">0.00</span>
        </p>
        <button type="button" class="cf f18 tc db" id="bmButtun"/>
        确认抵押</button>
    </section>

    <div class="theme-popover bcf">
        <div class="theme-poptit w100">
            <h3 class="tc f20 c3">风险提示</h3>
        </div>
        <div class="baitiaoLine" style="margin-top: 0;">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
            <p class="w100" style="background: #FFFFFF"></p>
            <p class="w100" style="background: #FFFFFF"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="theme-popbod c6 f14 lh15">
            <p>
                1. 众筹不是商品交易。支持者根据自己的判断选择、支持众筹项目，与发起人共同实现梦想并获得发起人承诺的回报，众筹存在一定风险。
            </p>
            <p class="mgt10">
                2.
                七彩云购平台只提供平台网络空间、技术服务和支持等中介服务。七彩云购平台作为居间方，并不是发起人或支持者中的任何一方，众筹仅存在于发起人和支持者之间，使用七彩云购平台台产生的法律后果由发起人与支持者自行承担。
            </p>
            <p class="mgt10">
                3. 众筹项目的回报发放、发票开具及其他后续服务事项均由发起人负责。如果发生发起人无法发放回报、延迟发放回报、不提供回报后续服务等情形，您需要直接和发起人协商解决，七彩云购平台对此不承担任何责任。
            </p>
            <p class="mgt10">
                4. 众筹项目一旦支付成功，在众筹期中将不予退款；众筹结束后，若众筹失败将原路退回；若众筹成功，支持者想退款，您需要直接与发起人协商解决，七彩云购平台对此不承担任何责任。
            </p>

        </div>
        <div class="theme-btn w100 of">
            <div class="of">
                <button type="button" class="fl tc close" style="background:#EC9E23;width:26%">放弃</button>
                <button type="button" onclick="confirmBorrow();" class="fr tc" style="background:#2B93EE;width:70%">
                    我已了解，确认抵押
                </button>
            </div>
        </div>
    </div>
    <div class="theme-popover-mask"></div>
</div>

<script>

    /**
     * 加载新数据
     */
    function getData() {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1751}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
                if (data.state == 1) {
                    // 刷新页面
                    refreshPage(data.list);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }

    function getItemHtml(data) {

        var rate = <%=cmahc.mortgagerate%>;
        var interes = <%=cmahc.mortgageinteres%>;
        var owermb = data.totalrmb * 1.00 * (rate / 100.00);

        var html = ''
                + '<section class="proSection pr w100 bcf">'
                + '<div class="w100 of clearfix">'
                + '<div class="checkboxFive fl">'
                + '<input type="checkbox" name="chkItem" value="' + data.totalrmb + "_" + owermb + '" id="' + data.orderid + '" />'
                + '<label for="' + data.orderid + '"></label>'
                + '</div>'
                + '<div class="fl" style="width: 84%">'
                + '<h5 class="f16 c3 lh16 fb" style="margin-top: 18px;">' + data.projectname + '</h5>'
                + '<p class="f12 c9">订单号 ' + data.order_sn + '</p>'
                + '<div class="bmInfo1 clearfix of w100">'
                + '<div class="pr" style="width: 55%">'
                + '<div class="pa h100" style="width: 1px;background: #EBEBEB;right: 0.5px;" ></div>'
                + '<div>'
                + '<h6 class="f12 c6">资产</h6>'
                + '<p class="c3" style="font-size: 20px;">￥' + data.totalrmb + '</p>'
                + '</div>'
                + '</div>'
                + '<div style="width:30%">'
                + '<div class="tc">'
                + '<h6 class="f12 c6">锁定期(天)</h6>'
                + '<p class="cff9933" style="font-size: 20px;">' + data.days + '</p>'
                + '</div>'
                + '</div>'
                + '</div>'
                + '<div class="bmInfo1 clearfix of w100" style="border-bottom: none">'
                + '<div style="width: 50%">'
                + '<div>'
                + '<h6 class="f12 c6">抵押获得金额</h6>'
                + '<p class="cred" style="font-size: 20px;">￥' + owermb + '</p>'
                + '</div>'
                + '</div>'
                + '<div  class="pr" style="width:30%">'
                + '<div class="pa h100" style="width: 1px;background: #EBEBEB;right: 0.5px;" ></div>'
                + '<div class="pa h100" style="width: 1px;background: #EBEBEB;left: 0.5px;" ></div>'
                + '<div class="tc">'
                + '<h6 class="f12 c6">月息</h6>'
                + '<p class="cff9933" style="font-size: 20px;">' + interes + '%</p>'
                + '</div>'
                + '</div>'
                + '<div style="width: 20%">'
                + '<div>'
                + '<h6 class="f12 c6">抵押率</h6>'
                + '<p class="cff9933" style="font-size: 20px;">' + rate + '%</p>'
                + '</div>'
                + '</div>'
                + '</div>'
                + '</div>'
                + '</div>'
                + '</section>'
                + '';

        return html;
    }

    /**
     * 刷新列表页面
     * @param data
     */
    function refreshPage(data) {
        if (data == null) {
            showToast("暂无订单抵押项目！");
            return;
        }

        var html = '';

        for (var i = 0; i < data.length; i++) {
            html += getItemHtml(data[i])
        }

        $("#container").html(html);

        chkChanged();
    }

    getData();

    $(function () {

        $('#bmButtun').click(function () {
            $('.theme-popover-mask').fadeIn();
            $('.theme-popover').slideDown();
        });

        $('.close').click(function () {
            $('.theme-popover-mask').fadeOut();
            $('.theme-popover').slideUp();
        });

    });

    // chkItem 事件
    function chkChanged() {
        $("[name = chkItem]:checkbox").bind("click", function () {

            var chks = $("input[name='chkItem']:checkbox:checked");

            // 计算总金额
            var totalrmb = 0.00;
            var totalowenrmb = 0.00;

            for (var i = 0; i < chks.length; i++) {
                var val1 = chks[i].value.split("_")[0];
                var val2 = chks[i].value.split("_")[1];
                totalrmb = totalrmb + (val1 * 1.00);
                totalowenrmb = totalowenrmb + (val2 * 1.00);
            }

            $("#totalrmb").text(totalrmb);
            $("#totalowenrmb").text(totalowenrmb);
        });
    }

    /**
     * 确认抵押
     */
    function confirmBorrow() {
        // 关闭风险提示对话框
        $('.theme-popover-mask').fadeOut();
        $('.theme-popover').slideUp();

        // 订单号列表
        var orderidlist = '';
        var chks = $("input[name='chkItem']:checkbox:checked");
        for (var i = 0; i < chks.length; i++) {
            orderidlist += chks[i].id + ",";
        }

        if (orderidlist.length > 0) {
            orderidlist = orderidlist.substring(0, orderidlist.length - 1);
        }

        if (orderidlist.length == 0) {
            showToast("请先选择要抵押的订单！")
            return;
        }

        // 提交抵押
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1756, orderidlist: orderidlist}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
                if (data.state == 1) {
                    // 存储需要刷新白条页面
                    localStorage.setItem("needrefreshbaitiao", 'true');

                    // 申请成功 关闭页面 回退
                    showTipDialog("提示", data.info, function () {
                        javascript:history.back();
                    }, 1);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }

</script>

</body>
</html>
